import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CmtNotifyNoticeApi } from '#/api/cmt/notify/notice';

import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';

import { z } from '#/adapter/form';
import { getRangePickerDefaultProps } from '#/utils';

export const NOTICE_TYPE_OPTIONS = [{ label: '通知', value: 1 }, { label: '公示', value: 2 }, { label: '政策', value: 3 }];
export const IS_TOP_OPTIONS = [{ label: '是', value: 1 }, { label: '否', value: 0 }];

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'title',
      label: '标题',
      rules: 'required',
      component: 'Input',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请输入标题',
      },
    },
    {
      fieldName: 'content',
      label: '内容',
      rules: 'required',
      component: 'Input',
      formItemClass: 'col-span-1',
      componentProps: {
        type: 'textarea',
        rows: 4,
        placeholder: '请输入内容',
      },
    },
    {
      fieldName: 'coverImage',
      label: '封面图片',
      component: 'ImageUpload',
      formItemClass: 'col-span-1',
    },
    {
      fieldName: 'noticeType',
      label: '公告类型',
      component: 'Select',
      formItemClass: 'col-span-1',
      componentProps: {
        options: NOTICE_TYPE_OPTIONS,
        placeholder: '请选择公告类型',
      },
    },
    {
      fieldName: 'isTop',
      label: '是否置顶',
      component: 'RadioGroup',
      formItemClass: 'col-span-1',
      componentProps: {
        options: IS_TOP_OPTIONS,
      },
    },
    {
      fieldName: 'publishTime',
      label: '发布时间',
      component: 'DatePicker',
      formItemClass: 'col-span-1',
      componentProps: {
        showTime: true,
        placeholder: '请选择发布时间',
      },
    },
    {
      fieldName: 'sort',
      label: '排序',
      component: 'InputNumber',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请输入{field_label}', controlsPosition: 'right', class: '!w-full',
      },
      defaultValue: 0,
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        clearable: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<CmtNotifyNoticeApi.NotifyNotice>['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    {
      field: 'id',
      title: 'ID',
      minWidth: 120,
    },
    {
      field: 'title',
      title: '标题',
      minWidth: 120,
    },
    {
      field: 'coverImage',
      title: '封面图片',
      minWidth: 120,
    },
    {
      field: 'noticeType',
      title: '公告类型',
      minWidth: 120,
    },
    {
      field: 'isTop',
      title: '是否置顶',
      minWidth: 120,
    },
    {
      field: 'viewCount',
      title: '浏览次数',
      minWidth: 120,
    },
    {
      field: 'publishTime',
      title: '发布时间',
      minWidth: 120,
    },
    {
      field: 'sort',
      title: '排序',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
